Import sidesign.minib3d
Import c3d.cal3d
Import c3d.calb3d
Import c3d.loader

Strict

Local width=1024,height=768,depth=0,mode=2

Graphics3D width,height,depth,mode

Local cam:TCamera=CreateCamera()
PositionEntity cam,0,10,-15

Local light:TLight=CreateLight()

Local calmodel:CB3DModel = New CB3DModel
Delta.targetfps = 30
calmodel.SetSkeleton(LoadXMLSkeleton(LoadBank("cube.xsf")))
calmodel.AddMesh(LoadXMLMesh(LoadBank("cube.xmf")))
'calmodel.AddMesh(LoadXMLMesh(LoadBank("paladin_cape1.xmf")))
calmodel.AddAnim(LoadXMLAnimation(LoadBank("cube.xaf"),calmodel.Skele))
calmodel.AddMorphAnim(LoadXMLMorphAnimation(LoadBank("cube.xpf")))

calmodel.AddMaterial(LoadXMLMaterial(LoadBank("cube.xrf")),0)
calmodel.Build()
calmodel.AnimateMorph(0)
calmodel.Animate(0)

'Local dt:DeltaTimer = DeltaTimer.CreateDelta(30)

Local anim_time#=0

' used by fps code
Local old_ms=MilliSecs()
Local renders=0
Local fps=0

While Not KeyDown(KEY_ESCAPE)		
	Delta.UpdateDelta()
	If KeyHit(KEY_ENTER) Then DebugStop

	' control camera
	MoveEntity cam,KeyDown(KEY_D)-KeyDown(KEY_A),0,KeyDown(KEY_W)-KeyDown(KEY_S)
	TurnEntity cam,KeyDown(KEY_DOWN)-KeyDown(KEY_UP),KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT),0

	If KeyDown(KEY_MINUS) Then anim_time#=anim_time#-0.1
	If KeyDown(KEY_EQUALS) Then anim_time#=anim_time#+0.1
	

	calmodel.Update(Delta.delta/30)
	RenderWorld
	renders=renders+1
	
	' calculate fps
	If MilliSecs()-old_ms>=1000
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf
	
	Text 0,0,"FPS: "+fps
	Text 0,20,"+/- to animate"


	Flip
	
Wend
End